package com.hnevc.androiduiclassone5;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Administrator on 2018/6/13.
 */

public class MyDialog extends Dialog {
    MainActivity mainActivity = new MainActivity();
    interface  OnCharge{
        void updateAmount(String amount);//用来更新车辆的余额
    }
    OnCharge onCharge;

    String carNumber="您好";

    TextView mtvcarnumber;
    Button mbtncharg;
    Button cancel;

    String amount;//输入的冲值金额
    EditText edAmount;

    public MyDialog(@NonNull Context context) {
        super(context);
    }

    public MyDialog(@NonNull Context context,String carNumber) {
        super(context);
        this.carNumber = carNumber;
    }

    public MyDialog(@NonNull Context context,String carNumber,OnCharge onCharge) {
        super(context);
        this.carNumber = carNumber;
        this.onCharge = onCharge;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.my_dialog);
        mtvcarnumber= findViewById(R.id.tv_carnumber);
        mtvcarnumber.setText(carNumber);
        mbtncharg=findViewById(R.id.btn_ok);
        edAmount=findViewById(R.id.ed_amount);
        cancel = findViewById(R.id.btn_cancel);
        mbtncharg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //冲值
                amount=edAmount.getText().toString();
                onCharge.updateAmount(amount);
                dismiss();

            }
        });
cancel.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        dismiss();
    }
});




    }

}
